package com.mapull.example.section1;

/**
 * StringIndexOf
 *
 * @author mapull
 * @date 2021-09-02
 * @since 1.0
 **/
public class StringIndexOf {

    public static void main(String[] args) {
        System.out.println("hello world".indexOf('o'));//4
        System.out.println("hello world".lastIndexOf('o'));//7
        System.out.println("hello world".lastIndexOf('a'));//-1
        System.out.println("长江大桥在长江上".lastIndexOf("长江"));//5
        System.out.println("hello world".lastIndexOf(null));//java.lang.NullPointerException
    }
    public static void main5(String[] args) {
        System.out.println("hello world".indexOf('e'));//1
        System.out.println("hello world".indexOf(101));//1
        System.out.println((int)'o');
    }
    public static void main4(String[] args) {
        System.out.println("hello world".indexOf('h',2));//-1
        System.out.println("hello world".indexOf(104,2));//-1
        System.out.println("hello world".indexOf('i',100));//-1
        System.out.println("hello world".indexOf(105,100));//-1
        System.out.println("hello world".indexOf('o',5));//7
        System.out.println("hello world".indexOf(111,5));//7
    }
    public static void main3(String[] args) {
        System.out.println("hello world".indexOf('h'));//0
        System.out.println("hello world".indexOf('i'));//-1
        System.out.println("hello world".indexOf('o'));//4
    }

    public static void main2(String[] args) {
        System.out.println("hello world, my world".indexOf("world"));//6
        System.out.println("hello world, my world".indexOf("world", 3));//6
        System.out.println("hello world, my world".indexOf("world", 10));//16
        System.out.println("hello world, my world".indexOf("world", 17));//-1
        System.out.println("hello world, my world".indexOf("world", 100));//-1
    }
    public static void main1(String[] args) {
        String name = "mapull.com";
        System.out.println(name.indexOf("pull"));//2
        System.out.println("hello world".indexOf("world"));//6
        System.out.println("hello world".indexOf("ok"));//-1
        System.out.println("你好".indexOf("好"));//1
        System.out.println("123".indexOf("23"));//1
        System.out.println("123123".indexOf("12"));//0
    }
}
